package bom.example.common.common;

import com.alibaba.fastjson.JSONObject;

/**
 * @author X.I.O
 * @title: Results
 * @projectName springboot
 * @description: TODO
 * @date 2021/10/27 17:04
 */
public class Results {

    private static JSONObject getJSONObject(){
        return new JSONObject();
    }

    public static JSONObject success(){
        JSONObject object= getJSONObject();
        object.put(Contants.CODE,0);
        object.put(Contants.MSG,Contants.SUCCESS);
        return object;
    }

    public static JSONObject success(String msg){
        JSONObject object=success();
        object.put(Contants.MSG,msg);
        return object;
    }

    public static JSONObject success(Object data){
        JSONObject object=success();
        object.put(Contants.DATA,data);
        return object;
    }

    public static JSONObject success(Object data,Object total){
        JSONObject object=success();
        object.put(Contants.DATA,data);
        object.put(Contants.TOTAL,total);
        return object;
    }

    public static JSONObject error(){
        JSONObject object= getJSONObject();
        object.put(Contants.CODE,1);
        object.put(Contants.MSG,Contants.ERROR);
        return object;
    }

    public static JSONObject error(String msg){
        JSONObject object=error();
        object.put(Contants.MSG,msg);
        return object;
    }
}
